$(function() {
	admin.userHelp.init();
});
Namespace('admin.userHelp', {
	init : function() {
		easyui.util.initDatagrid('#datagrid', {
			onDblClickRow : function() {
			}
		});
	},
	query : function() {
		if (!$('#query-form').form('validate'))
			return;
		var data = $('#query-form').form('jsonObject');
		$('#datagrid').datagrid('load', data);
	},
	
	toAdd:function() {
		top.addTab("1",'添加', contextPath+'/user/help/toAdd');
	},
	
	add:function () {
	 	if(!$('#data-form').form('validate')) return;
        var data=$('#data-form').form('jsonObject');
        var url = contextPath + '/user/help/add';
		$.post(url, data, function (result) {
			$('#datagrid').datagrid('loaded');
			if (result.code == 1) {
				top.showInfo('创建成功');
				top.addTab("",'用户帮助表', contextPath+'/user/help/list');
			} else {
				top.showInfo(result.msg);
			}
		});
	},
	
	toUpdate:function(id) {
		if (id != null) {
			top.addTab(id,'编辑', contextPath+'/user/help/toUpdate?id=' + id);
		}
	},
	
	update: function () {
	 	if(!$('#data-form').form('validate')) return;
        var data=$('#data-form').form('jsonObject');
        var url = contextPath + '/user/help/update';
        $('#datagrid').datagrid('loading');
		$.post(url, data, function (result) {
			 $('#datagrid').datagrid('loaded');
			if (result.code == 1) {
				top.showInfo('编辑成功');
				top.addTab("1",'用户帮助表', contextPath+'/user/help/list');
			} else {
				top.showInfo(result.msg);
			}
		});
	},
	
	unclaimed:function(id) {
		var url = contextPath + '/user/help/unclaimed';
        $('#datagrid').datagrid('loading');
		$.post(url, {id:id}, function (result) {
			 $('#datagrid').datagrid('loaded');
			if (result.code == 1) {
				top.showInfo('删除成功');
				top.addTab("1",'用户帮助表', contextPath+'/user/help/list');
			} else {
				top.showInfo(result.msg);
			}
		});
	},
	
	receive:function(id) {
		var url = contextPath + '/user/help/receive';
        $('#datagrid').datagrid('loading');
		$.post(url, {id:id}, function (result) {
			 $('#datagrid').datagrid('loaded');
			if (result.code == 1) {
				top.showInfo('恢复成功');
				top.addTab("1",'用户帮助表', contextPath+'/user/help/list');
			} else {
				top.showInfo(result.msg);
			}
		});
	},
	
	netMsgChange:function(id,maxCount) {
		var inputLength = $('#'+id).val().length;
		if (inputLength == 0) {
			$('#'+id+'_txt').html(maxCount+'个字以内，还可以输入' + maxCount + '个字');
			saveFlag = false;
		} else if (inputLength > 0 && inputLength <= maxCount) {
			$('#'+id+'_txt').html(maxCount+'个字以内，还可以输入' + (maxCount - inputLength) + '个字');
			saveFlag = false;
		} else if (inputLength > maxCount) {
			$('#'+id+'_txt').html(maxCount+'个字以内，已经输入超过<strong class="cred">' + (inputLength - maxCount) + '</strong>个字');
			saveFlag = true;
		}
	},
});